﻿using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using IDAL;
using Model;

namespace DAL
{
    public class ZTEPIMAndPower : BaseRepository<ZTEPIMAndPowerInfo>, IZTEPIMAndPower
    {
        #region 静态变量部分
        private const string PARM_ZTEPIMANDPOWER_ID = "@ID";
        private const string PARM_ZTEPIMANDPOWER_PRODUCTTYPEID = "@ProductTypeID";
        private const string PARM_ZTEPIMANDPOWER_TESTTYPE = "@TestType";
        private const string PARM_ZTEPIMANDPOWER_TESTITEM = "@TestItem";
        private const string PARM_ZTEPIMANDPOWER_TESTPORT = "@TestPort";
        private const string PARM_ZTEPIMANDPOWER_TESTTARGET = "@TestTarget";
        private const string PARM_ZTEPIMANDPOWER_ISPASS = "@IsPass";

        private const string PARM_ZTEPIMANDPOWER_PRODUCTSN = "@ProductSN";
        #endregion

        #region 数据检索部分
        public IList<ZTEPIMAndPowerInfo> LoadEntities()
        {
            return ExcuteSqlToGetEntities("ZTEPIMAndPower_select");
        }

        public ZTEPIMAndPowerInfo LoadEntity<T1>(T1 Id)
        {
            SqlParameter parm = GetParameter();
            parm.Value = Id;
            return ExcuteSqlToGetEntity("ZTEPIMAndPower_selectbyID",parm);
        }

        /// <summary>
        /// 判断某产品类型的某测试类型下的测试项目是否已经存在
        /// </summary>
        /// <param name="productTypeID"></param>
        /// <param name="testType"></param>
        /// <param name="testItem"></param>
        /// <returns></returns>
        public ZTEPIMAndPowerInfo GetZTEPIMandPowerbyPIDTTTI(string productTypeID,string testType,string testItem)
        {
            SqlParameter[] parms = GetPIDTTTIParameter();
            parms[0].Value = productTypeID;
            parms[1].Value = testType;
            parms[2].Value = testItem;
            return ExcuteSqlToGetEntity("ZTEPIMAndPower_selectbyPIDTTTI", parms);
        }

        public IList<ZTEPIMAndPowerInfo> GetZTEPIMbySN(string productSN)
        {
            SqlParameter parm = GetSNParameter();
            parm.Value = productSN;
            return ExcuteSqlToGetEntities("ZTEPIMAndPower_selectPIMbySN",parm);
        }

        public IList<ZTEPIMAndPowerInfo> GetZTEPowerbySN(string productSN)
        {
            SqlParameter parm = GetSNParameter();
            parm.Value = productSN;
            return ExcuteSqlToGetEntities("ZTEPIMAndPower_selectPowerbySN",parm);
        }
        #endregion

        #region 参数部分
        public SqlParameter GetSNParameter()
        {
            SqlParameter Parm = new SqlParameter(PARM_ZTEPIMANDPOWER_PRODUCTSN, SqlDbType.NVarChar, 50);
            return Parm;
        }

        public SqlParameter[] GetPIDTTTIParameter()
        {
            SqlParameter[] Parms = null;
            Parms = new SqlParameter[]
                {
                    new SqlParameter(PARM_ZTEPIMANDPOWER_PRODUCTTYPEID, SqlDbType.NVarChar, 50),
                    new SqlParameter(PARM_ZTEPIMANDPOWER_TESTTYPE, SqlDbType.NVarChar, 50),
					new SqlParameter(PARM_ZTEPIMANDPOWER_TESTITEM, SqlDbType.NVarChar, 50), 
                };
            return Parms;
        }
        #endregion


        #region 重写基类部分
        //-------------------------------------重写超类基础操作---------------------------------------------------------
        public override ZTEPIMAndPowerInfo GetEntityRecord(SqlDataReader rdr)
        {
            ZTEPIMAndPowerInfo pro = new ZTEPIMAndPowerInfo()
            {
                ID = rdr.GetInt32(0),
                ProductTypeID = rdr.GetValue(1).ToString(),
                TestType = rdr.GetValue(2).ToString(),
                TestItem = rdr.GetValue(3).ToString(),
                TestPort = rdr.GetValue(4).ToString(),
                TestTarget = rdr.GetValue(5).ToString(),
                IsPass = rdr.GetValue(6).ToString()
            };
            return pro;
        }

        public override ZTEPIMAndPowerInfo GetEntityRecord()
        {
            ZTEPIMAndPowerInfo pro = new ZTEPIMAndPowerInfo();
            return pro;
        }

        public override string GetInsertsp()
        {
            return "ZTEPIMAndPower_Insert";
        }

        public override string GetUpdatesp()
        {
            //暂时不实现更新功能
            return null;
        }

        public override string GetDeletesp()
        {
            return "ZTEPIMAndPower_Delete";
        }

        public override SqlParameter GetParameter()
        {
            SqlParameter Parm = new SqlParameter(PARM_ZTEPIMANDPOWER_ID, SqlDbType.Int, 4);
            return Parm;
        }

        public override SqlParameter[] GetParameters()
        {
            SqlParameter[] parms = null;
            parms = new SqlParameter[]
                {
					new SqlParameter(PARM_ZTEPIMANDPOWER_ID, SqlDbType.Int, 4),
					new SqlParameter(PARM_ZTEPIMANDPOWER_PRODUCTTYPEID, SqlDbType.NVarChar, 50),
                    new SqlParameter(PARM_ZTEPIMANDPOWER_TESTTYPE, SqlDbType.NVarChar, 50),
					new SqlParameter(PARM_ZTEPIMANDPOWER_TESTITEM, SqlDbType.NVarChar, 50), 
                    new SqlParameter(PARM_ZTEPIMANDPOWER_TESTPORT, SqlDbType.NVarChar, 50),
					new SqlParameter(PARM_ZTEPIMANDPOWER_TESTTARGET, SqlDbType.NVarChar, 50),  
                    new SqlParameter(PARM_ZTEPIMANDPOWER_ISPASS, SqlDbType.NVarChar, 10), 
                };
            return parms;
        }

        public override void SetParameters(ZTEPIMAndPowerInfo customer, params SqlParameter[] Parms)
        {
            Parms[0].Value = customer.ID;
            Parms[1].Value = customer.ProductTypeID;
            Parms[2].Value = customer.TestType;
            Parms[3].Value = customer.TestItem;
            Parms[4].Value = customer.TestPort;
            Parms[5].Value = customer.TestTarget;
            Parms[6].Value = customer.IsPass;
        }
        #endregion
    }
}